<template>
  <a-config-provider :locale="locale">
    <div id="app">
      <router-view />
    </div>
  </a-config-provider>
</template>

<script>
import { domTitle, setDocumentTitle } from '@/utils/domUtil'
import { i18nRender } from '@/locales'

export default {
  data () {
    return {
    }
  },
  computed: {
    locale () {
      // 只是为了切换语言时，更新标题
      const { title } = this.$route.meta
      title && (setDocumentTitle(`${i18nRender(title)} - ${domTitle}`))

      return this.$i18n.getLocaleMessage(this.$store.getters.lang).antLocale
    }
  },
  methods: {
    // 根据fullUrl清除keepAlive
    // clearKeepAlive (fullUrl) {
    //   // console.log('bus触发要清除的keepAlive', fullUrl);
    //   // var cache = this.$vnode.componentInstance.cache
    //   // var keys = this.$vnode.componentInstance.keys
    //   // console.log(cache)
    //   // console.log(keys)
    //   this.$children.forEach((item) => {
    //     console.log(item.$vnode)
    //     if (item.$vnode.data.text === fullUrl || (item.$vnode.data.text && item.$vnode.data.text.indexOf(fullUrl) >= 0)) {
    //       console.log(item.$vnode.data.text)
    //       this._myDestory(item)
    //     }
    //   })
    // },
    // // 封装清除某个组件的keepAlive状态,并销毁
    // _myDestory (keepAliveComponent) {
    //   // 你可以根据自己的业务更改此处的判断逻辑，酌情决定是否摧毁本层缓存。
    //   if (keepAliveComponent.$vnode && keepAliveComponent.$vnode.data.keepAlive) {
    //     if (keepAliveComponent.$vnode.parent && keepAliveComponent.$vnode.parent.componentInstance && keepAliveComponent.$vnode.parent.componentInstance.cache) {
    //       if (keepAliveComponent.$vnode.componentOptions) {
    //         var key = keepAliveComponent.$vnode.key == null ? keepAliveComponent.$vnode.componentOptions.Ctor.cid +
    //           (keepAliveComponent.$vnode.componentOptions.tag ? `::${keepAliveComponent.$vnode.componentOptions.tag}` : '') : keepAliveComponent.$vnode.key
    //         var cache = keepAliveComponent.$vnode.parent.componentInstance.cache
    //         var keys = keepAliveComponent.$vnode.parent.componentInstance.keys
    //         if (cache[key]) {
    //           if (keys.length) {
    //             var index = keys.indexOf(key)
    //             if (index > -1) {
    //               keys.splice(index, 1)
    //             }
    //           }
    //           delete cache[key]
    //         }
    //       }
    //     }
    //   }
    //   keepAliveComponent.$destroy()
    // }
  }
  // mounted () {
  //   // 注册监听全局的clearKeepAlive方法,可在其他组件中触发此方法
  //   this.$bus.$on('clearKeepAlive', this.clearKeepAlive)
  // }
}
</script>
